package com.yloveg.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yloveg.dao.SuserMapper;
import com.yloveg.entity.Suser;
import com.yloveg.entity.UserExtend;
import com.yloveg.service.UserService;

@Service
public class UserServiceImpl implements UserService {
 
    @Autowired
    private SuserMapper SuserMapper;

	public Suser findUserByNameAndPassword(String username) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("username", username);
		List<Suser> userList = SuserMapper.selectByMap(map);
		if(userList.size()!=1) {
			return null;
		}else{
			return userList.get(0);
		}
	}

	@Override
	public int registerUser(Suser user) {
		// TODO Auto-generated method stub
		user.setState(1);
		user.setCreateDate(new Date());
		return SuserMapper.insert(user);
	}

	@Override
	public int updateByPrimaryKeySelective(Suser record) {
		// TODO Auto-generated method stub
		return SuserMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public PageInfo<UserExtend> queryUserPage(int page, int limit,Map<String,Object> map) {
		// TODO Auto-generated method stub
	    PageHelper.startPage(page, limit);
	    List<UserExtend> listUser = SuserMapper.querySUser(map);
	    PageInfo<UserExtend> resultPage = new PageInfo<UserExtend>(listUser);
	    return resultPage;
	}

	@Override
	public Suser findUserById(Long id) {
		// TODO Auto-generated method stub
		return SuserMapper.selectByPrimaryKey(id);
	}
 
 


}
